package com.ruoyi.riv.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.DataScope;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.riv.domain.RiverInfo;
import com.ruoyi.riv.service.IRiverInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 河流信息Controller
 * 
 * @author ruoyi
 * @date 2024-10-24
 */
@RestController
@RequestMapping("/riv/info")
public class RiverInfoController extends BaseController
{
    @Autowired
    private IRiverInfoService riverInfoService;

    /**
     * 查询河流信息列表
     */
    @PreAuthorize("@ss.hasPermi('riv:info:list')")
    @GetMapping("/list")
    @DataScope(userAlias = "u")
    public TableDataInfo list(RiverInfo riverInfo)
    {
        startPage();
        List<RiverInfo> list = riverInfoService.selectRiverInfoList(riverInfo);
        return getDataTable(list);
    }

    /**
     * 导出河流信息列表
     */
    @PreAuthorize("@ss.hasPermi('riv:info:export')")
    @Log(title = "河流信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RiverInfo riverInfo)
    {
        List<RiverInfo> list = riverInfoService.selectRiverInfoList(riverInfo);
        ExcelUtil<RiverInfo> util = new ExcelUtil<RiverInfo>(RiverInfo.class);
        util.exportExcel(response, list, "河流信息数据");
    }

    /**
     * 获取河流信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('riv:info:query')")
    @GetMapping(value = "/{riverId}")
    public AjaxResult getInfo(@PathVariable("riverId") Long riverId)
    {
        return success(riverInfoService.selectRiverInfoByRiverId(riverId));
    }

    /**
     * 新增河流信息
     */
    @PreAuthorize("@ss.hasPermi('riv:info:add')")
    @Log(title = "河流信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RiverInfo riverInfo)
    {
        return toAjax(riverInfoService.insertRiverInfo(riverInfo));
    }

    /**
     * 修改河流信息
     */
    @PreAuthorize("@ss.hasPermi('riv:info:edit')")
    @Log(title = "河流信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RiverInfo riverInfo)
    {
        return toAjax(riverInfoService.updateRiverInfo(riverInfo));
    }

    /**
     * 删除河流信息
     */
    @PreAuthorize("@ss.hasPermi('riv:info:remove')")
    @Log(title = "河流信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{riverIds}")
    public AjaxResult remove(@PathVariable Long[] riverIds)
    {
        return toAjax(riverInfoService.deleteRiverInfoByRiverIds(riverIds));
    }
}
